# -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from osv import fields, osv, orm
import tools
import logging
import addons
import datetime

class village_government_salary(orm.Model):
    """村干部 年度工作报酬公开表"""
    _name = 'village.government.salary'
    _description = '村干部 年度工作报酬公开表'
    
    _columns = {
        'company_id': fields.many2one('res.company', '村', required=True, readonly=True),
        'year': fields.integer('年度', required=True),
        'publish_date': fields.date('公布日期', readonly=True),
        'state': fields.selection([('draft', '草稿'), ('done', '公布')], '状态', readonly=True),
        'lines': fields.one2many('village.governement.salary.line', 'parent_id', '明细行', states={'done': [('readonly', True)]})
    }
    
    _defaults = {
        'company_id': lambda self, cr, uid, c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
        'year': datetime.date.today().year,
        'state': 'draft'
        }
    
    def submit(self, cr, uid, ids, context=None):
        self.get_pool("village.government.salary").write(cr, uid, ids, {'state': 'done'})
        return True;
    
class village_government_salary_line(orm.Model):
    """村干部 年度工作报酬明细行"""    
    _name = 'village.government.salary.line'
    _description = '明细行'
    
    def _calc_sub_total(self, cr, uid, ids, name, arg, context=None):

        """ Calculates Sub total
        @param name: Names of fields.
        @param arg: User defined arguments
        @return: Dictionary of values.
        """
        res = {}
        for obj in self.browse(cr, uid, ids, context=context):
            res[obj.id] = obj.basic_salary + obj.bonus + obj.allowance
        return res
            
    _columns = {
        'parent_id': fields.many2one('village.government.salary', required=True, ondelete='cascade', select=True),
        'name': fields.char('姓名', size=20, required=True),
        'position': fields.char('职务', size=20, required=True),
        'basic_salary': fields.float('基本报酬', digits=(16,2)),
        'bonus': fields.float('考核报酬', digits=(16,2)),
        'allowance': fields.float('其它补贴', digits=(16,2)),
        'subtotal': fields.function(_calc_sub_total, string='报酬合计', digits=(16,2)),
        'notes': fields.text('备注')
    }

class village_family_planning(orm.Model):
    """村计划生育情况公开表"""
    _name = 'village.family.planning'
    _description = '村计划生育情况公开表'
    
    _columns = {
        'company_id': fields.many2one('res.company', '村', required=True, readonly=True),
        'year': fields.integer('年度', required=True),
        'season': fields.integer('季度', required=True),
        'publish_date': fields.date('公布日期'),
        'state': fields.selection([('draft', '草稿'), ('done', '公布')], '状态'),
        'approved_lines': fields.one2many('village.family.planning.approved.line', 'parent_id', '符合条件批准再生育情况', states={'done': [('readonly', True)]}),
        'violation_lines': fields.one2many('village.family.planning.violation.line', 'parent_id', '不符合法定条件生育情况', states={'done': [('readonly', True)]}),
        'award_lines': fields.one2many('village.family.planning.award.line', 'parent_id', '符合条件享受奖励扶助情况', states={'done': [('readonly', True)]})
     }
    
    _defaults = {
        'company_id': lambda self, cr, uid, c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
        'year': datetime.date.today().year,
        'season': (datetime.date.today().month / 3 + 1),
        'state': 'draft'
        }    
    
    def submit(self, cr, uid, ids, context=None):
        self.get_pool("village.family.planning").write(cr, uid, ids, {'state': 'done'})
        return True;
            
class village_family_planning_approved_line(orm.Model): 
    """符合条件批准再生育情况"""    
    _name = "village.family.planning.approved.line"
    _description = "符合条件批准再生育情况"
    
    _columns = {
        'parent_id': fields.many2one('village.family.planning', required=True, ondelete='cascade', select=True),
        'husband': fields.char('丈夫', size=20, required=True),
        'wife': fields.char('妻子', size=20, required=True),
        'address': fields.char('家庭住址', size=50, required=True),
        'approve_date': fields.date('批准日期', required=True)
    }    
        
class village_family_planning_violation_line(orm.Model):   
    """不符合法定条件生育情况"""    
    _name = "village.family.planning.violation.line"
    _description = "不符合法定条件生育情况"
    
    _columns = {
        'parent_id': fields.many2one('village.family.planning', required=True, ondelete='cascade', select=True),
        'husband': fields.char('丈夫', size=20, required=True),
        'wife': fields.char('妻子', size=20, required=True),
        'address': fields.char('家庭住址', size=50, required=True),
        'bear_date': fields.date('生育时间', required=True)
    }
    
class village_family_planning_award_line(orm.Model):
    """符合条件享受奖励扶助情况"""    
    _name = "village.family.planning.award.line"
    _description = "符合条件享受奖励扶助情况"
       
    _columns = {
        'parent_id': fields.many2one('village.family.planning', required=True, ondelete='cascade', select=True),
        'target': fields.char('奖励对象', size=20, required=True),
    }
  
class village_pension(orm.Model):
    """优待抚恤发放情况"""
    _name = 'village.pension'
    _description = '优待抚恤发放情况'
    
    _columns = {
        'company_id': fields.many2one('res.company', '村', required=True, readonly=True),
        'year': fields.integer('年度', required=True),
        'publish_date': fields.date('公布日期'),
        'state': fields.selection([('draft', '草稿'), ('done', '公布')], '状态'),
        'lines': fields.one2many('village.pension.line', 'parent_id', '明细行', states={'done': [('readonly', True)]})
    }
    
    _defaults = {
        'company_id': lambda self, cr, uid, c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
        'year': datetime.date.today().year,
        'state': 'draft'
        }       
    
    def submit(self, cr, uid, ids, context=None):
        self.get_pool("village.pension").write(cr, uid, ids, {'state': 'done'})
        return True;
                
class village_pension_line(orm.Model):
    """优待抚恤发放情况明细行"""    
    _name = 'village.pension.line'
    _description = '优待抚恤发放情况明细行'
            
    _columns = {
        'parent_id': fields.many2one('village.pension', required=True, ondelete='cascade', select=True),
        'name': fields.char('姓名', size=20, required=True),
        'category': fields.selection([('A', 'A、“三属”(烈士遗属、因公牺牲军人遗属、病故军人遗属)'),
                                      ('B', 'B、在乡伤残军人'),
                                      ('C', 'C、在乡老复员军人'),
                                      ('D', 'D、带病回乡退伍军人'),
                                      ('E', 'E、参战退役人员'),
                                      ('F', 'F、义务兵家属'),
                                      ('G', 'G、老复员军人配偶')], '属别', required=True),
        'amount': fields.float('金额（元)', digits=(16,2)),
        'notes': fields.text('备注')
    }
    
  
class village_assistance(orm.Model):
    """最低生活保障、救灾救济款物发放情况公开表"""
    _name = 'village.assistance'
    _description = '最低生活保障、救灾救济款物发放情况公开表'
    
    _columns = {
        'company_id': fields.many2one('res.company', '村', required=True, readonly=True),
        'year': fields.integer('年度', required=True),
        'publish_date': fields.date('公布日期'),
        'state': fields.selection([('draft', '草稿'), ('done', '公布')], '状态'),
        'five_guarantees_lines': fields.one2many('village.assistance.five.guarantees', 'parent_id', states={'done': [('readonly', True)]}),
        'disaster_lines': fields.one2many('village.assistance.disaster', 'parent_id', states={'done': [('readonly', True)]}),
        'low_income_lines': fields.one2many('village.assistance.low.income', 'parent_id', states={'done': [('readonly', True)]}),
        'special_lines': fields.one2many('village.assistance.special', 'parent_id', states={'done': [('readonly', True)]})
    }
    
    _defaults = {
        'company_id': lambda self, cr, uid, c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
        'year': datetime.date.today().year,
        'state': 'draft'
        }      
    
    def submit(self, cr, uid, ids, context=None):
        self.get_pool("village.assistance").write(cr, uid, ids, {'state': 'done'})
        return True;
        
class village_assistance_five_guarantees(orm.Model):
    """五保户最低生活保障、救灾救济款物发放情况明细行"""    
    _name = 'village.assistance.five.guarantees'
    _description = '五保户最低生活保障、救灾救济款物发放情况明细行'
            
    _columns = {
        'parent_id': fields.many2one('village.assistance', required=True, ondelete='cascade', select=True),
        'name': fields.char('对象', size=20, required=True),
        'address': fields.char('供养地点', size=50, required=True),
        'amount': fields.float('金额（元)', digits=(16,2)),
        'notes': fields.text('备注')
    }
    
class village_assistance_disaster(orm.Model):
    """受灾户最低生活保障、救灾救济款物发放情况明细行"""    
    _name = 'village.assistance.disaster'
    _description = '受灾户最低生活保障、救灾救济款物发放情况明细行'
            
    _columns = {
        'parent_id': fields.many2one('village.assistance', required=True, ondelete='cascade', select=True),
        'name': fields.char('对象', size=20, required=True),
        'address': fields.char('供养地点', size=50, required=True),
        'amount': fields.float('年供养金额', digits=(16,2)),
        'notes': fields.text('备注')
    }

class village_assistance_low_income(orm.Model):
    """低保户最低生活保障、救灾救济款物发放情况明细行"""    
    _name = 'village.assistance.low.income'
    _description = '低保户最低生活保障、救灾救济款物发放情况明细行'
            
    _columns = {
        'parent_id': fields.many2one('village.assistance', required=True, ondelete='cascade', select=True),
        'name': fields.char('对象', size=20, required=True),
        'address': fields.char('家庭地址', size=50, required=True),
        'amount': fields.float('救助金额', digits=(16,2)),
        'notes': fields.text('备注')
    }
    
class village_assistance_special(orm.Model):
    """特殊群体最低生活保障、救灾救济款物发放情况明细行"""    
    _name = 'village.assistance.special'
    _description = '特殊群体最低生活保障、救灾救济款物发放情况明细行'
            
    _columns = {
        'parent_id': fields.many2one('village.assistance', required=True, ondelete='cascade', select=True),
        'name': fields.char('对象', size=20, required=True),
        'address': fields.char('事由情况', size=50, required=True),
        'amount': fields.float('金额', digits=(16,2)),
        'notes': fields.text('备注')
    }
    
    
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
